home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2159 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: access4.digex.net!not-for-mail
  2. From: ell@access4.digex.net (Ell)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Doesn't work, Why EXACTLY?
  5. Date: 16 Jan 1996 02:36:33 GMT
  6. Organization: The Universe
  7. Message-ID: <4df2vh$q92@news4.digex.net>
  8. References: <30FA8289.7AD6@bangate.compaq.com>
  9. NNTP-Posting-Host: access4.digex.net
  10. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  11.  
  12. Saurabh Dixit (saurabhd@bangate.compaq.com) wrote:
  13. : class X {
  14. : };
  15. : class Y : public X {
  16. : };
  17. : class Base {
  18. : public:
  19. :     void func1(int a);
  20. :     void func2(X* x);
  21. : };
  22. : class Derived : public Base {
  23. : public:
  24. :     void func1(float b);
  25. :     void func2(Y* y);
  26. : };
  27. : when I call func2 from a Derived object with a pointer
  28. : to an X object, i get - "... cannot convert from X to Y...".
  29. : So looks like compiler looks at method func2() in Derived
  30. : class.  I would think the signature of the call would make
  31. : it look in Base class.
  32. : On the lines of func1() i thought it would work.
  33. : Please note that I don't want func2() to be virtual.
  34. : I need func2() to do to distinct operations depending on
  35. : what type of object was fed to it?
  36.  
  37. What you describe is the standard way C++ works.
  38.  
  39. The handle/body, and letter/envelope idioms explained in James Coplien's
  40. Advanced C++ may help you to do what you desire in C++.
  41.  
  42. Elliott
  43.